// Example usage.
// This script generates a numerical control with max/minimum values
//var objIntControl = new numberSelectControl($('#numOutput'), 10, 20, 40);
//objIntControl.out()	

function numberSelectControl(container, min, current, max){

	this.container = container;
	this.min = min;
	this.current = current;
	this.max = max;
	this.stepping = 1;
	this.controlID;
	
	var objectRef = this;
	
	this.setStepping = function(stepping){
		this.stepping = stepping;
	}
	
	this.out = function(){
		// Generate an ID for this control.
		this.controlID = Math.floor( Math.random() * 100);

		var minusLink = $("<a />", 
			{ href: '#', click: function(e){ objectRef.changeVal(objectRef.stepping * -1) } })
			.append($("<img>", 
				{ 'src' : PicBoard.baseURL + "images/minus.png", border: 0 })
		);

		var plusLink = $("<a />", 
			{ href: '#', click: function(e){ objectRef.changeVal(objectRef.stepping) } })
			.append($("<img>", 
				{ 'src' : PicBoard.baseURL + "images/plus.png", border: 0 })
		);
		
		numDisplay = $("<span>", { 'id': 'intX' + objectRef.controlID, 'text': objectRef.current });
		
		
		$(this.container).html("");
		$(this.container).append(minusLink).append(numDisplay).append(plusLink);

		return "intX" + objectRef.controlID;
	}
	
	this.changeVal = function(factor){
		var newVal = parseInt(this.current + factor);
		this.setVal(newVal);
	}
	
	this.setVal = function(newVal){
		if(newVal > this.min && newVal < this.max){
			$('#intX' + objectRef.controlID).text(newVal);
			objectRef.current = newVal;
			return true;
		} else {
			return false;
		}
	}
	
	this.getVal = function(){
		return objectRef.current;
	}
	
};